

//
//  CouponsCell.m
//  LuxuryGoods
//
//  Created by DCQ on 2018/5/23.
//  Copyright © 2018年 Future. All rights reserved.
//

#import "CouponsCell.h"
#import "CouponsListModel.h"
@interface  CouponsCell()
@property (weak, nonatomic) IBOutlet UILabel *couponsName;
@property (weak, nonatomic) IBOutlet UIImageView *stateImgV;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UIButton *userBtn;
@property (weak, nonatomic) IBOutlet UILabel *parValueLabel;
@property (weak, nonatomic) IBOutlet UILabel *conditionLabel;
@property (weak, nonatomic) IBOutlet UIImageView *bgImgV;
@property (weak, nonatomic) IBOutlet UILabel *markLabel;

@end
@implementation CouponsCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.userBtn.layer.masksToBounds = YES;
    self.userBtn.layer.cornerRadius = 13;
    self.userBtn.layer.borderColor = [UIColor clearColor].CGColor;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (void)setupData:(id)data  withStyle:(CouponsCellStyle)style{
    
    CouponsModel *model =  data;
    BOOL stateImgVHidden = NO;
    BOOL userBtnHideen = NO;
    NSString * stateImgName = @"";
    UIColor * textColor  = UIColorFromRGB(0xDAB35F);
    NSString * bgImgName = @"youhuiquan_shiyonghou";
    UIColor * bgColor = UIColorFromRGB(0xDAB35F);
    UIColor * couponsTextColor = UIColorFromRGB(0x666666);
    if (style == CouponsCellStyle_overdue) {
        userBtnHideen = YES;
        stateImgVHidden = NO;
        stateImgName = @"youhuiquan_guoqi";
        textColor = UIColorFromRGB(0xCDCDCD);
        bgColor = UIColorFromRGB(0xCDCDCD);
        couponsTextColor = UIColorFromRGB(0xCDCDCD);
    }else if (style == CouponsCellStyle_used){
        userBtnHideen = YES;
        stateImgName = @"hongbao_shiyong";
        textColor = UIColorFromRGB(0xCDCDCD);
        bgColor = UIColorFromRGB(0xCDCDCD);
        couponsTextColor = UIColorFromRGB(0xCDCDCD);
    }else if (style == CouponsCellStyle_noUsed){
        userBtnHideen = NO;
        stateImgName = @"";
        bgImgName = @"youhuiquan_weishiyong";
        
    }
    self.stateImgV.hidden = stateImgVHidden;
    self.userBtn.hidden = userBtnHideen;
    self.stateImgV.image = [UIImage imageNamed:stateImgName];
 
    self.parValueLabel.text = [NSString stringWithFormat:@"%@",model.par_value];
    self.conditionLabel.text = [NSString stringWithFormat:@"满%@可以使用",model.use_condition];
    self.couponsName.text = model.goods_ids;
    self.timeLabel.text = [NSString stringWithFormat:@"%@-%@",[self timeFormat: model.createtime],[self timeFormat:model.expirytime]];
    self.bgImgV.image = [UIImage imageNamed:bgImgName];
    self.parValueLabel.textColor = self.conditionLabel.textColor = self.markLabel.textColor = textColor ;
    self.userBtn.backgroundColor = bgColor ;
    self.couponsName.textColor = couponsTextColor ;
}

- (NSString *)timeFormat:(NSString *)timeStr{
    NSString * tempStr = timeStr;
    if (timeStr ) {
        if (timeStr.length >= 10) {
            tempStr = [timeStr substringToIndex:10];
        }
    }else{
        tempStr = @"";
    }
    
    return tempStr;
    return tempStr;
    
}
- (IBAction)userAction:(id)sender {
    if (self.block) {
        self.block(self.indexPath);
    }
}

@end
